package com.xr.sunnyday.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.xr.sunnyday.dao.MemberDao;
import com.xr.sunnyday.pojo.Member;
import com.xr.sunnyday.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberDao memberDao;

    /**
     * 通过手机号码查询会员信息
     */
    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    /**
     * 添加会员
     */
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    @Override
    public List<Integer> getMemberReport(List<String> months) {
        //定义一个返回的List<Integer>
        List<Integer> memberCount = new ArrayList<Integer>();
        //每个月查询一下，查询12次
        for (int i = 0; i < months.size(); i++) {
            //拿到每个月
            String month = months.get(i);
            //根据月份查每个月的数量
            Integer count = memberDao.findMemberCountBeforeDate(month);
            memberCount.add(count);
        }
        return memberCount;
    }
}
